package jaux.tank.bean.vo.front;

import java.util.Optional;

public class Rets {

    public static final String DATA_NOT_PRESENT_MSG = "目标不存在";
	public static final Integer SUCCESS_CODE = 20000;
    public static final Integer WARNING_CODE = 7777;
    public static final Integer FAILURE_CODE = 9999;
    public static final  String DEFAULT_SUCCESS_MSG = "成功";

    private Rets() {}
    
    public static  <T> Ret<T> success(T data) {
		return new Ret<>(Rets.SUCCESS_CODE, DEFAULT_SUCCESS_MSG, data);
    }
    
    public static <T> Ret<T> of(Optional<T> opt){
    	if(opt.isPresent()) {
    		return new Ret<>(Rets.SUCCESS_CODE, DEFAULT_SUCCESS_MSG, opt.get());
    	}
    	return new Ret<>(Rets.FAILURE_CODE, DATA_NOT_PRESENT_MSG, null);
    }
    public static <T> Ret<T> warning(String msg,T data) {
    	return new Ret<>(Rets.WARNING_CODE, msg, data);
    }

    public static <T> Ret<T> failure(String msg) {
        return new Ret<>(Rets.FAILURE_CODE, msg, null);
    }

    public static <T> Ret<T> success() {
        return new Ret<>(Rets.SUCCESS_CODE, DEFAULT_SUCCESS_MSG, null);
    }
}
